package org.dfl.plugin.editor.figures;

import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.MidpointLocator;
import org.eclipse.draw2d.PolygonDecoration;
import org.eclipse.draw2d.PolylineConnection;
import org.eclipse.draw2d.Graphics;

/**
 * connection figure that represents an edge
 * @author Piotr Wlodarczyk
 *
 */
public class ConnectionFigure extends PolylineConnection{
	private Label propertiesLabel;
//	private Label inputLabel;
	
	private String propertiesString = "";
	private String inputString = "";
	
	public ConnectionFigure() {
		super();
		setTargetDecoration(new PolygonDecoration());
		setLineStyle(Graphics.LINE_SOLID);
		
		MidpointLocator labelLocator = new MidpointLocator(this, 0);
		propertiesLabel = new Label("");
		this.add(propertiesLabel, labelLocator);

		// use this to add endpoint locator
//		ConnectionEndpointLocator inputLabelLocator = new ConnectionEndpointLocator(this, true);
//		inputLabelLocator.setUDistance(10);
//		inputLabelLocator.setVDistance(-10);
//		inputLabel = new Label("");
//		this.add(inputLabel, inputLabelLocator);
	}
		
	public void setInputLabel(String name){
		inputString = name;
		refreshLabel();
	}
	
	public void setPropertiesLabel(String name){
		propertiesString = name;
		refreshLabel();
	}
	
	private void refreshLabel() {
		propertiesLabel.setText(inputString+"\n"+propertiesString);
		
	}
}
